package com.zhlb.zfba.modules.sys.service;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhlb.zfba.modules.card.bean.CardRegInfo;
import com.zhlb.zfba.modules.card.service.CardRegInfoService;
import com.zhlb.zfba.modules.per.bean.PoliceInfo;
import com.zhlb.zfba.modules.per.bean.SuspectInfo;
import com.zhlb.zfba.modules.per.bean.UserInfo;
import com.zhlb.zfba.modules.per.dao.PoliceInfoDao;
import com.zhlb.zfba.modules.per.service.UserInfoService;

@Service
@Transactional(readOnly = true)
public class SysService {
	@Autowired 
	UserInfoService userInfoService;
	public String loginAuth(UserInfo userInfo,HttpServletRequest request) {
		String loginID	= null;
		String password	= null;
		HttpSession session = null;
		UserInfo userInfoData=null;
		String errMsg="";
			loginID  = userInfo.getLoginName();
			password = userInfo.getPassword();
			if (null == loginID ||"".equals(loginID) ||"".equals(password)||null == password) {
				if (null != session) {
					userInfoData =(UserInfo)session.getAttribute("userInfoData");
				}
				if (null == userInfoData) {
					return "用户和密码不能为空！";
				} else {
					return "";
				}
			} else {
				session = request.getSession(false);
				if (null != session) {
					session.invalidate();
				}
				session = request.getSession(true);

				loginID = loginID.trim();
				password = password.trim();
				userInfoData=userInfoService.getByLoginName(loginID);
				if (null == userInfoData) {
					return "用户不存在！";
				}
				String F_PassWord = userInfoData.getPassword();

				if (!F_PassWord.equals(password)) {
					
					return "密码错误！";
				}
				session.setAttribute("userInfoData", userInfoData);
				return "";
			}
		}
}
